library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidytuesdayR)
library(ggplot2)
library(dplyr)
library(ggthemes)
library(maps)
##
## Attaching package: 'maps'
##
## The following object is masked from 'package:purrr':
##
## map
library(sf)
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(cartography)
## This project is in maintenance mode.
## Core functionalities of `cartography` can be found in `mapsf`.
## https://riatelab.github.io/mapsf/
library(RColorBrewer)
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
shapenames <- read_sf( "CA_Counties", "CA_Counties_TIGER2016")
jail_America <- readr::read_csv("./Allstatesinsurvey/all_jails.csv")
## Rows: 523 Columns: 116
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (18): statecode, state, state_notes, county, jail, jail_notes, med2008, ...
## dbl (98): id, fips, d2008, d2009, d2010, d2011, d2012, d2013, d2014, d2015, ...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
jail_deaths_in_Americas <- readr::read_csv("./Allstatesinsurvey/all_deaths.csv")
## Rows: 7571 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (18): state, county, jail, date_of_death, full_name, last_name, first_na...
## dbl (4): id, year, yob, age
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
California_deaths <-jail_deaths_in_Americas %>%
filter(state=="CA")%>%
group_by(county)%>%
summarize(total_deaths = n())
#counts how many rows inside that group
California_deaths$total_deaths <- as.factor(California_deaths$total_deaths)
prisondeath<-shapenames %>%
left_join( California_deaths, by=c( "NAME"= "county"))
color_scale <- c("Low" = "yellow", "Mid" = "white", "High" = "red")
map <- ggplot(data= prisondeath, aes(fill= total_deaths)) +
geom_sf(fill="white", color="black",size = 0.1)+
labs(x="Latitude of California", y="Lonigitude of California", title= "Prison Death rates in California By County", subtitle = "Created:Ridwan Osman", fill="Total Deaths",)+
geom_sf_text(mapping = aes(label= NAME), size=1.5)+
scale_fill_manual( values = color_scale,
aesthetics = "fill",
breaks = waiver(),
na.value = "grey50")+
scale_size_discrete(range=c(6,12))+
theme_classic()+
theme(legend.title = element_text("Total Deaths"),axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1), text=element_text(family="Times New Roman"),plot.title = element_text(face="bold"), panel.background = element_rect(fill = "aliceblue"))+
coord_sf(crs = st_crs(3857))+
labs( subtitle="Created:Ridwan Osman",)
## Warning: Using size for a discrete variable is not advised.
ggplotly(map)
California_deaths$total_deaths <- as.factor(California_deaths$total_deaths)
ggsave("map.png", plot = map, width = 8, height = 6, dpi = 300)